package payrechargelogic

import (
	"context"

	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/recharge"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeChannelInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRechargeChannelInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeChannelInfoLogic {
	return &RechargeChannelInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// RechargeChannelInfo 充值渠道
func (l *RechargeChannelInfoLogic) RechargeChannelInfo(in *rpc.RechargeChannelInfoRequest) (*rpc.RechargeChannelInfoResponse, error) {
	var commonResp rpc.CommonResp
	channelInfo, err := model.NewRechargeChannelModel(l.ctx, l.svcCtx.Db).GetRechargeChannelById(in.Id)
	if err != nil {
		commonResp.Code = xerrors.DBError
		commonResp.Message = err.Error()
		return &rpc.RechargeChannelInfoResponse{
			CommonResp: &commonResp,
		}, err
	}

	return &rpc.RechargeChannelInfoResponse{
		Id:           channelInfo.ID,
		CreatedAt:    channelInfo.CreatedAt,
		UpdatedAt:    channelInfo.UpdatedAt,
		MappingCode:  channelInfo.MappingCode,
		Type:         channelInfo.Type,
		Name:         channelInfo.Name,
		Level:        channelInfo.Level,
		UserGroup:    channelInfo.UserGroup,
		BonusRate:    channelInfo.BonusRate,
		MinAmount:    channelInfo.MinAmount,
		MaxAmount:    channelInfo.MaxAmount,
		AmountConfig: channelInfo.AmountConfig,
		MerchantId:   channelInfo.MerchantID,
		AppId:        channelInfo.AppId,
		AppCode:      channelInfo.AppCode,
		SecretKey:    channelInfo.SecretKey,
		Url:          channelInfo.URL,
		ReturnUrl:    channelInfo.ReturnUrl,
		NotifyUrl:    channelInfo.NotifyUrl,
		PubKey:       channelInfo.PubKey,
		PrivateKey:   channelInfo.PrivateKey,
		StartTime:    channelInfo.StartTime,
		EndTime:      channelInfo.EndTime,
		Sort:         channelInfo.Sort,
		Status:       channelInfo.Status,
		IsTestable:   channelInfo.IsTestable,
		WhiteList:    channelInfo.WhiteList,
		Remark:       channelInfo.Remark,
		CommonResp:   &commonResp,
		Icon:         channelInfo.Icon,
		ChannelName:  channelInfo.ChannelName,
		Inr:          channelInfo.Coin,
	}, nil
}
